<?php

namespace app\admin\model\product;

use think\Model;
use traits\model\SoftDelete;

class Product extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'product';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';



    // 追加属性
    protected $append = [
        'deploy_type_text'
    ];



    public function getDeployTypeList()
    {
        return ['1' => __('cpu'), '2' => __('主板'), '3' => __('显卡'), '4' => __('内存'), '5' => __('硬盘')
            , '6' => __('电源'), '7' => __('散热'), '8' => __('机箱'), '9' => __('显示器'), '10' => __('配件'),
            '11' => __('外设')];
    }


    public function getDeployTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['deploy_type']) ? $data['deploy_type'] : '');
        $list = $this->getDeployTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }



    public function attr()
    {
        return $this->belongsTo('Attr', 'attr_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


}
